﻿
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Uipath_License.Uc;

namespace Uipath_License
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Page_Change.Content = new Frame()
            {
                Content = new UC_Home()
            };
        }

        public MainWindow(string theCurrentVersion)
        {
            InitializeComponent();
            Page_Change.Content = new Frame()
            {
                Content = new UC_Home()
            };
            TheCurrentVersion.Header = "当前版本:V" + theCurrentVersion;
        }

        private void Get_License_Menu_MouseUp(object sender, MouseButtonEventArgs e)
        {
            //if (Main_Header.Header == (sender as SideMenuItem)?.Header)
            //{
            //    return;
            //}
            //Main_Header.Header = (sender as SideMenuItem)?.Header;
            Page_Change.Content = new Frame()
            {
                Content = new UC_GetLicense()
            };
        }

        private void Manage_License_Menu_MouseUp(object sender, MouseButtonEventArgs e)
        {
            //if (Main_Header.Header == (sender as SideMenuItem)?.Header)
            //{
            //    return;
            //}
            //Main_Header.Header = (sender as SideMenuItem)?.Header;
            Page_Change.Content = new Frame()
            {
                Content = new UC_ManageLicense()
            };
        }

        private void Home_Mneu_MouseUp(object sender, MouseButtonEventArgs e)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            //if (Main_Header.Header == (sender as SideMenuItem)?.Header)
            //{
            //    return;
            //}
            //Main_Header.Header = (sender as SideMenuItem)?.Header;
            Page_Change.Content = new Frame()
            {
                Content = new UC_Home()
            };
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Process.GetCurrentProcess().Kill();
            GC.Collect();
            Environment.Exit(0);
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBoxResult button = HandyControl.Controls.MessageBox.Show("确认关闭吗？", "提醒", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (button == MessageBoxResult.Yes)
            {
                Process.GetCurrentProcess().Kill();
                GC.Collect();
                Environment.Exit(0);
            }
            else
            {
                e.Cancel = true;
            }
        }



        /// <summary>
        /// 窗体关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Closing_Button_Click(object sender, RoutedEventArgs e)
        {
            Window_Closing(null, null);

        }

        private void Closing_Button_Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            Window_Closing(null, null);
        }

        private void Min_Button_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void Min_Button_Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void Versions_MouseUp(object sender, MouseButtonEventArgs e)
        {
            //System.Diagnostics.Process.Start(new ProcessStartInfo("http://ck23456.cn")
            GC.Collect();
            GC.WaitForPendingFinalizers();
            //{ UseShellExecute = true});
            Page_Change.Content = new Frame()
            {
                //Content = new ChromiumWebBrowser() { Address = "http://ck23456.cn/Uipath_License_File/UpdateLog.html" }
            };

        }

        private void Explain_MouseUp(object sender, MouseButtonEventArgs e)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            //System.Diagnostics.Process.Start(new ProcessStartInfo("http://ck23456.cn")
            //{ UseShellExecute = true});
            Page_Change.Content = new Frame()
            {
                Content = new UC_HistoryUpdateLog()
            };
        }

        private void Shortcut_Menu_MouseUp(object sender, MouseButtonEventArgs e)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            Page_Change.Content = new Frame()
            {
                Content = new UC_Shortcut()
            };
        }
    }
}
